/**
 * @projectName study-note
 * @package Iterator
 * @className Iterator.ConcreteGather
 */
package Iterator;

/**
 * ConcreteGather
 * @description 具体迭代类
 * @author answer_wx
 * @date 2022/7/4 10:58
 * @version 1.0
 */
public class ConcreteIterator<T> implements Iterator {
    private ConcreteGather<T> gather;
    private int current = 0;

    public ConcreteIterator(ConcreteGather<T> gather) {
        this.gather = gather;
    }

    @Override
    public T first() {
        return gather.get(0);
    }

    @Override
    public T next() {
        T t = null;
        current++;
        if (current < gather.count()) {
            t = gather.get(current);
        }
        return t;
    }

    @Override
    public T current() {
        return gather.get(current);
    }

    @Override
    public boolean isDone() {
        return current >= gather.count() ? true : false;
    }
}